package com.ethink.platform.controller;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.platform.manager.OssTemplateManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author meiping
 * @date 2022-03-16
 */
@Tag(name = "FileController", description = "文件上传下载")
@RestController
@RequestMapping("/platform-server/v1/file")
public class FileController extends BaseController {

    @Autowired
    private OssTemplateManager ossTemplateManager;

    @Operation(summary = "文件上传")
    @PostMapping("/upload/{bizType}")
    public CommonResponse fileUpload(@RequestParam("file") MultipartFile file, @PathVariable String bizType) {
        Map<String, String> response = ossTemplateManager.upload(file, bizType);
        return succeedWith(response);
    }

    @PostMapping("batchUpload/{bizType}")
    @Operation(summary = "批量文件上传")
    public CommonResponse fileBatchUpload(MultipartFile[] file, @PathVariable String bizType) {
        ossTemplateManager.batchUpload(file, bizType);
        return succeed();
    }

}
